package com.yunnuo.monitor.job.manager;

import org.quartz.Scheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Created by w_weihf on 2018/10/25.
 */
@Configuration
public class QuartzConfig {
    private JobFactory jobFactory;
    public QuartzConfig(JobFactory jobFactory){
        this.jobFactory = jobFactory;
    } /**
    * 配置SchedulerFactoryBean
     *
    * 将一个方法产生为Bean并交给Spring容器管理
    */
   @Bean
   public SchedulerFactoryBean schedulerFactoryBean() {
       // Spring提供SchedulerFactoryBean为Scheduler提供配置信息,并被Spring容器管理其生命周期
       // 设置自定义Job Factory，用于Spring管理 Job bean
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setJobFactory(jobFactory);
       return factory;
   }

    @Bean(name = "scheduler")
    public Scheduler scheduler() {
           return schedulerFactoryBean().getScheduler();
    }
}
